home *** CD-ROM | disk | FTP | other *** search
Wrap
// This file was generated by Dashcode from Apple Inc. // You may edit this file to customize your Dashboard widget. var cmd1; var numofitems; var date; var itemAnimator; var scrollArea; var scrollBar; var scrollAreaDiv; var droparea; var growboxInset; var updateTimer; // // Function: load() // Called by HTML body element's onload event when the widget is ready to start // function load() { setupParts(); droparea = document.getElementById('droparea'); scrollAreaDiv = document.getElementById('scrollArea'); cmd1 = new Object(); numofitems = 0; itemAnimator = new AppleAnimator(500, 13); scrollBar = new AppleVerticalScrollbar(document.getElementById("scrollBar")); scrollArea = new AppleScrollArea(document.getElementById("scrollArea")); scrollBar.setTrackStart('Images/trackTop.png', 9); scrollBar.setTrackMiddle('Images/trackMiddle.png'); scrollBar.setTrackEnd('Images/trackBottom.png', 9); scrollBar.setThumbStart('Images/thumbTop.png', 12); scrollBar.setThumbMiddle('Images/thumbMiddle.png'); scrollBar.setThumbEnd('Images/thumbBottom.png', 12); scrollArea.singlepressScrollPixels = 3; scrollArea.addScrollbar(scrollBar); if (widget.preferenceForKey('lhostrhistory') != null) { scrollAreaDiv.innerHTML = widget.preferenceForKey('lhostrhistory'); scrollArea.refresh(); } if (widget.preferenceForKey('lhwidgetheight') != null) { setTimeout("adjustWidgetHeight(widget.preferenceForKey('lhwidgetheight'), 338, 1)", 700); } var images = scrollAreaDiv.getElementsByTagName("img"); for (var f = 0; f<images.length; f++) { images[f].onload = function(event) { scrollArea.refresh(); } } if (widget.preferenceForKey('username') != null) { document.getElementById("username").value = widget.preferenceForKey('username'); document.getElementById("password").value = 'pswdissekrit'; verifyOnLoad(null); } if (widget.preferenceForKey('updatesOnOff') == '1' || widget.preferenceForKey('updatesOnOff') == undefined) { checkForUpdates(null); document.getElementById('updatesOnOff').checked = true; } else { document.getElementById('updatesOnOff').checked = false; } if (widget.preferenceForKey('autocopy') == '1') { document.getElementById('copyOnOff').checked = true; } else { document.getElementById('copyOnOff').checked = false; } } // // Function: remove() // Called when the widget has been removed from the Dashboard // function remove() { // Stop any timers to prevent CPU usage // Remove any preferences as needed // widget.setPreferenceForKey(null, createInstancePreferenceKey("your-key")); widget.setPreferenceForKey(null, createInstancePreferenceKey("username")); widget.setPreferenceForKey(null, createInstancePreferenceKey("password")); widget.setPreferenceForKey(null, createInstancePreferenceKey("lhwidgetheight")); widget.setPreferenceForKey(null, createInstancePreferenceKey("lhostrhistory")); } // // Function: hide() // Called when the widget has been hidden // function hide() { // Stop any timers to prevent CPU usage } // // Function: show() // Called when the widget has been shown // function show() { // Restart any timers that were stopped on hide } // // Function: sync() // Called when the widget has been synchronized with .Mac // function sync() { // Retrieve any preference values that you need to be synchronized here // Use this for an instance key's value: // instancePreferenceValue = widget.preferenceForKey(null, createInstancePreferenceKey("your-key")); // // Or this for global key's value: // globalPreferenceValue = widget.preferenceForKey(null, "your-key"); } // // Function: showBack(event) // Called when the info button is clicked to show the back of the widget // // event: onClick event from the info button // function showBack(event) { var front = document.getElementById("front"); var back = document.getElementById("back"); adjustWidgetHeight(338, 0, 0); setTimeout(function(){ if (window.widget) { widget.prepareForTransition("ToBack"); } front.style.display = "none"; back.style.display = "block"; if (window.widget) { setTimeout('widget.performTransition();', 100); } }, 1); } // // Function: showFront(event) // Called when the done button is clicked from the back of the widget // // event: onClick event from the done button // function showFront(event) { var front = document.getElementById("front"); var back = document.getElementById("back"); if (widget.preferenceForKey('lhwidgetheight') != null) { adjustWidgetHeight(widget.preferenceForKey('lhwidgetheight'), 0, 0); setTimeout('scrollArea.refresh()', 1); } if (window.widget) { widget.prepareForTransition("ToFront"); } front.style.display="block"; back.style.display="none"; if (window.widget) { setTimeout('widget.performTransition();', 0); } } if (window.widget) { widget.onremove = remove; widget.onhide = hide; widget.onshow = show; widget.onsync = sync; } function dragdrop (event) { var uri = null; try { uri = event.dataTransfer.getData("text/uri-list"); // attempt to load the new } catch (ex) // image { } // if the acquisition is successful: if (uri && uri.length>0) { event.stopPropagation(); event.preventDefault(); startUpload(uri); } else { event.stopPropagation(); event.preventDefault(); alert('An error occured'); droparea.style.opacity = 0; document.getElementById('uploading').style.opacity = 0; setTimeout(function(){dropareaAnimator = new AppleAnimator(1000, 26); dropareaAnimation = new AppleAnimation(0.0, 1.0, function(animation, current, start, finish) { droparea.style.opacity = current; }); dropareaAnimator.addAnimation(dropareaAnimation); dropareaAnimator.start();}, 5000); setTimeout("document.getElementById('uploading').style.opacity = 1;", 6000); } } function dragenter (event) { event.stopPropagation(); event.preventDefault(); } function dragover (event) { event.stopPropagation(); event.preventDefault(); } function dragleave (event) { event.stopPropagation(); event.preventDefault(); } function basename(path, suffix) { // http://kevin.vanzonneveld.net // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) // + improved by: Ash Searle (http://hexmen.com/blog/) // + improved by: Lincoln Ramsay // + improved by: djmix // * example 1: basename('/www/site/home.htm', '.htm'); // * returns 1: 'home' var b = path.replace(/^.*[\/\\]/g, ''); if (typeof(suffix) == 'string' && b.substr(b.length-suffix.length) == suffix) { b = b.substr(0, b.length-suffix.length); } return b; } function startUpload (localuri) { var cancelimage = document.getElementById('cancel'); droparea.style.opacity=0; cancelimage.style.display = "block"; if (numofitems == 0) cmd1 = new Object(); localuri = localuri.split('\n'); for (key in localuri) { var newlocaluri = localuri[key].replace(/file:\/\/localhost/, ''); var filename = basename(newlocaluri.replace(/\%20/g, ' ')); newlocaluri = newlocaluri.replace(/\%20/g, '\\ '); newlocaluri = newlocaluri.replace(/\&/g, '\\&'); if (newlocaluri.substr(-1,1) != '/') { command = '/usr/bin/curl -F Filedata=@' + newlocaluri + ' -F "username=' + widget.preferenceForKey('username') + '" -F "hashed_password=' + widget.preferenceForKey('password') + '" http://www.localhostr.com/api'; alert(command); cmd1[key] = widget.system(command, finishUpload); numofitems = numofitems + 1; } else { alert('Is a directory'); droparea.style.opacity = 0; document.getElementById('uploading').style.opacity = 0; if (numofitems == 0 && localuri.length <= 1) { cancelimage.style.display = "none"; setTimeout(function(){dropareaAnimator = new AppleAnimator(1000, 26); dropareaAnimation = new AppleAnimation(0.0, 1.0, function(animation, current, start, finish) { droparea.style.opacity = current; }); dropareaAnimator.addAnimation(dropareaAnimation); dropareaAnimator.start();}, 5000); } setTimeout("document.getElementById('uploading').style.opacity = 1;", 6000); } } } function cancelFileUpload (event) { var cancelimage = document.getElementById('cancel'); for (key in cmd1) { cmd1[key].cancel(); } cmd1 = new Object(); droparea.style.opacity = 1; cancelimage.style.display = "none"; numofitems = 0; } function finishUpload (command) { file = command.outputString.split(','); filename = basename(file[0]); date = new Date(); var cancelimage = document.getElementById('cancel'); var uploadTarget = scrollAreaDiv; var uploadArea = scrollArea; file[0] = file[0].replace(/ /g, '+'); icon = 'http://localhostr.com' + file[1]; icon = icon.replace(/ /g, '+'); var newHTML = generateFileHTML(file[0], filename, icon, date); uploadTarget.innerHTML = newHTML + uploadTarget.innerHTML; // This code was "inspired" by the SVN Revision widget // http://lab.arc90.com/2008/04/svn_notifier.php var growlcmd = '/usr/bin/osascript growl.scpt "Your file, ' + filename + ', has been uploaded successfully"'; cmd2 = widget.system(growlcmd, function(){null}); if (widget.preferenceForKey('lhwidgetheight') == 192) { adjustWidgetHeight(265, 192, 0); setTimeout("adjustWidgetHeight(192, 265, 0)", 20000); } widget.setPreferenceForKey(uploadTarget.innerHTML, 'lhostrhistory'); if ((numofitems == 1) && (document.getElementById('copyOnOff').checked == true)) { widget.system("/bin/echo -n '" + file[0] + "' | pbcopy", null); alert('copied URL'); } numofitems = numofitems - 1; var images = scrollAreaDiv.getElementsByTagName("img"); for (var f = 0; f<images.length; f++) { images[f].onload = function(event) { scrollArea.refresh(); } } scrollArea.refresh(); if (numofitems == 0) { dropareaAnimator = new AppleAnimator(1000, 26); dropareaAnimation = new AppleAnimation(0.0, 1.0, function(animation, current, start, finish) { droparea.style.opacity = current; }); dropareaAnimator.addAnimation(dropareaAnimation); dropareaAnimator.start(); cancelimage.style.display = 'none'; } } function copyURL(url, objreference) { widget.system("/bin/echo -n '" + url + "' | pbcopy", null); objreference.innerText = 'URL COPIED'; setTimeout(function(){objreference.innerText = '+ COPY URL'}, 5000); } function generateFileHTML(url, filename, icon, date) { var displayDate = getSimpleDate(date); if (filename.length > 25) { filename = filename.substr(0,25); filename += '...'; } var newHTML = '<div id="' + date + '" class="container" valign="middle" style="opacity:1;">'; newHTML = newHTML + '<div class="thumbDiv" valign="middle"><img src="' + icon + '" class="thumb"></div>'; newHTML = newHTML + '<div class="fileinfo">' newHTML = newHTML + '<h1>' + filename + '</h1>'; newHTML = newHTML + '<div class="filedate">' + displayDate + '</div>'; newHTML = newHTML + '<div class="copyurl" onclick="' + "copyURL('" + url + "', this)" + '">+ COPY URL</div>'; newHTML = newHTML + '</div>'; newHTML = newHTML + '</div>'; return newHTML; } function clear() { scrollAreaDiv.innerHTML = ''; widget.setPreferenceForKey('', 'lhostrhistory'); scrollArea.refresh(); showFront(); } function getSimpleDate(date) { var months = new Array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'); var days = new Array('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'); var month = months[date.getMonth()]; var dayofmonth = date.getDate(); var day = days[date.getDay()]; var year = date.getFullYear(); if (date.getMinutes() < 10) { var minutes = '0' + date.getMinutes(); } else { var minutes = date.getMinutes(); } var time = date.getHours() + ':' + date.getMinutes(); var newdate = day + ', ' + month + ' ' + dayofmonth + ', ' + year + ', ' + time; return newdate; } function verify(event) { document.getElementById("loginstatus").innerHTML = 'Please wait, verifying...'; var username = document.getElementById("username"); var password = document.getElementById("password"); // Values you provide var URL = "http://localhostr.com/api_verify"; // The feed to fetch var onloadHandler = function() { xmlLoaded(xmlRequest, username, password); }; // The function to call when the feed is loaded; currently calls the XMLHttpRequest load snippet var hashed = widget.system("/bin/echo -n '" + password.value + "' | /usr/bin/openssl dgst -sha1 ", null).outputString; // XMLHttpRequest setup code var xmlRequest = new XMLHttpRequest(); xmlRequest.onload = onloadHandler; xmlRequest.open("POST", URL); xmlRequest.setRequestHeader("Cache-Control", "no-cache"); xmlRequest.send("username=" + username.value + "&hashed_password=" + hashed); } function verifyOnLoad(event) { document.getElementById("loginstatus").innerHTML = 'Please wait, verifying...'; var username = document.getElementById("username"); var hashed = widget.preferenceForKey('password'); // Values you provide var URL = "http://localhostr.com/api_verify"; // The feed to fetch var onloadHandler = function() { xmlLoaded(xmlRequest, username, 'hashed'); }; // The function to call when the feed is loaded; currently calls the XMLHttpRequest load snippet // XMLHttpRequest setup code var xmlRequest = new XMLHttpRequest(); xmlRequest.onload = onloadHandler; xmlRequest.open("POST", URL); xmlRequest.setRequestHeader("Cache-Control", "no-cache"); xmlRequest.send("username=" + username.value + "&hashed_password=" + hashed); } // Called when an XMLHttpRequest loads a feed; works with the XMLHttpRequest setup snippet function xmlLoaded(xmlRequest, username, password) { if (xmlRequest.status == 200) { // Parse and interpret results // XML results found in xmlRequest.responseXML // Text results found in xmlRequest.responseText if(xmlRequest.responseText == 'found') { widget.setPreferenceForKey(username.value, 'username'); if (password != 'hashed') var hashed = widget.system('/bin/echo -n "' + password.value + '" | /usr/bin/openssl dgst -sha1 ', null).outputString; widget.setPreferenceForKey(hashed, 'password'); document.getElementById("loginstatus").innerHTML = "<span style='color:#6dff6c'>User Verfied</span>"; } else document.getElementById("loginstatus").innerHTML = xmlRequest.responseText; } else { alert("Error fetching data: HTTP status " + xmlRequest.status); } } function mouseDown(event) { document.addEventListener("mousemove", mouseMove, true); document.addEventListener("mouseup", mouseUp, true); growboxInset = {x:(window.innerWidth - event.x), y:(window.innerHeight - event.y)}; event.stopPropagation(); event.preventDefault(); } function mouseMove(event) { var y = event.y + growboxInset.y; adjustWidgetHeight(y, 0, 1) event.stopPropagation(); event.preventDefault(); } function adjustWidgetHeight(y, animate, permenant) { if (animate <= 0) { if (y < 265 && y > 228) { y = 265; document.getElementById('scrollBar').style.display = 'block'; } else if (y < 228) { y = 192; document.getElementById('scrollBar').style.display = 'none'; } else { document.getElementById('scrollBar').style.display = 'block'; } document.getElementById("resize").style.top = (y-53); window.resizeTo(317,y); scrollAreaDiv.style.height = y-192 + 'px'; document.getElementById('scrollBar').style.height = y-192 + 'px'; scrollArea.refresh(); if (permenant > 0) widget.setPreferenceForKey(y.toString(), 'lhwidgetheight'); } else { if (y < 265 && y >= 228) { y = 265; document.getElementById('scrollBar').style.display = 'block'; } else if (y < 228) { y = 192; document.getElementById('scrollBar').style.display = 'none'; } else { document.getElementById('scrollBar').style.display = 'block'; } currentAnimator = new AppleAnimator(500, 13); currentAnimation = new AppleAnimation(animate, y, resizeAnimator); currentAnimator.addAnimation(currentAnimation); currentAnimator.start(); function resizeAnimator(animation, current, start, finish) { window.resizeTo(317,current); document.getElementById("resize").style.top = (current-53); scrollAreaDiv.style.height = current-192 + 'px'; document.getElementById('scrollBar').style.height = current-192 + 'px'; scrollArea.refresh(); } if (permenant > 0) widget.setPreferenceForKey(y.toString(), 'lhwidgetheight'); } } function mouseUp(event) { document.removeEventListener("mousemove", mouseMove, true); document.removeEventListener("mouseup", mouseUp, true); event.stopPropagation(); event.preventDefault(); } function checkForUpdates(event) { alert('Checking for updates...'); // Values you provide var URL = "http://simon360.com/localhostr/latestversion.php"; // The feed to fetch var onloadHandler = function() { updateResponse(xmlRequest); }; // The function to call when the feed is loaded; currently calls the XMLHttpRequest load snippet // XMLHttpRequest setup code var xmlRequest = new XMLHttpRequest(); xmlRequest.onload = onloadHandler; xmlRequest.open("POST", URL); xmlRequest.setRequestHeader("Cache-Control", "no-cache"); xmlRequest.send(null); } function updateResponse(xmlRequest) { if (xmlRequest.status == 200) { // Parse and interpret results // XML results found in xmlRequest.responseXML // Text results found in xmlRequest.responseText responseStuff = xmlRequest.responseText.split(','); if (responseStuff[0] > 1.10) { document.getElementById('updateAvailable').style.display="block"; document.getElementById('updateAvailable').onclick = function(){widget.openURL(responseStuff[1])}; document.getElementById('updateAvailable').style.cursor='pointer'; alert('Update available!'); } else { updateTimer = setTimeout("checkForUpdates()", 3600000); alert('No updates available.'); } } else { alert("Error fetching data: HTTP status " + xmlRequest.status); } } function toggleUpdates(event) { if (document.getElementById('updatesOnOff').checked == true) { widget.setPreferenceForKey('1', 'updatesOnOff') alert('Updates on'); checkForUpdates(null); } else { widget.setPreferenceForKey('0', 'updatesOnOff'); clearTimeout(updateTimer); alert('Updates off'); } } function toggleCopy(event) { if (document.getElementById('copyOnOff').checked == true) { widget.setPreferenceForKey('1', 'autocopy') alert('Autocopy on'); } else { widget.setPreferenceForKey('0', 'autocopy'); clearTimeout(updateTimer); alert('Autocopy off'); } }